#include "comboboxwidget.h"
#include "ui_ComboBoxWidget.h"
#include "controls/combobox/cximuticombobox.h"
#include "controls/combo//cximuticomb.h"
#include <QDebug>
ComboBoxWidget::ComboBoxWidget(QWidget* parent) : QWidget(parent), ui(new Ui::ComboBoxWidget)
{
	ui->setupUi(this);
	initCombobox();
	// initComb();
}

ComboBoxWidget::~ComboBoxWidget()
{
	delete ui;
}
void ComboBoxWidget::initCombobox()
{
	m_comb = new CxiMutiComboBox(this);
	m_comb->setGeometry(10, 10, 300, 30);
	m_comb->setMinimumWidth(400);

	QList<ComboItem> items;

	// ====== 添加学科测试数据 ======
	items.append(ComboItem("语文", "chinese", QVariant("主修"), {"文言文", "现代文", "阅读"}));
	items.append(ComboItem("数学", "math", QVariant("主修"), {"代数", "几何", "微积分"}));
	items.append(ComboItem("英语", "english", QVariant("主修"), {"英语口语", "英语听力", "写作"}));
	items.append(ComboItem("物理", "physics", QVariant("选修"), {"力学", "电磁学", "光学"}));
	items.append(ComboItem("化学", "chemistry", QVariant("选修"), {"有机化学", "无机化学", "反应"}));
	items.append(ComboItem("生物", "biology", QVariant("选修"), {"遗传学", "细胞学", "生态"}));
	items.append(ComboItem("政治", "politics", QVariant("文科"), {"思想政治", "哲学", "法治"}));
	items.append(ComboItem("历史", "history", QVariant("文科"), {"中国史", "世界史", "近代史"}));
	items.append(ComboItem("地理", "geography", QVariant("文科"), {"自然地理", "人文地理"}));
	items.append(ComboItem("信息技术", "it", QVariant("科技"), {"编程", "计算机", "人工智能"}));

	// ====== 加入多选下拉框 ======
	m_comb->addItems(items);
	m_comb->addItem(ComboItem("语文", "chinese", QVariant("主修"), {"文言文", "现代文", "阅读"}));
	connect(ui->getDatasBtn, &QPushButton::clicked, [this]() {
		auto datas = m_comb->getDatas();
		for (int i = 0; i < datas.size(); ++i) {
			qDebug().noquote() << QString("data[%1]: %2").arg(i).arg(datas[i]);
		}
	});

	connect(ui->getTagsBtn, &QPushButton::clicked, [this]() {
		auto tags = m_comb->getTags();
		for (int i = 0; i < tags.size(); ++i) {
			QString msg = QString("tag[%1]: %2").arg(i).arg(tags[i].toString());
			qDebug().noquote() << msg.toLocal8Bit().constData();
		}
	});

	for(int i = 0;i<1200;i++){
		QString display = QString("%1").arg(i);
		QString data = QString("%1").arg(i);
		QVariant tag = i;
		QVector<QString> filterWords = {display};
		ComboItem item = ComboItem(display,data,tag,filterWords);
		ui->cxiMutiComboBox->addItem(item);
	}
}
void ComboBoxWidget::initComb()
{
	m_combl = new CXiMutiComb(this);
	for(int i = 0;i<210;i++){
		QString display = QString("%1").arg(i);
		QString data = QString("%1").arg(i);
		QVariant tag = i;
		MutiItem item = MutiItem(display,data,tag);
		m_combl->addItem(item);
	}


}

